using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decisions.HL7.Message;
using DecisionsFramework;

namespace Decisions.HL7.Message
{
    public class InterpretationCodesAttribute:RuleAttribute
    {
        private Dictionary<HL7Version, string[]> validVersionCodes = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, string[]> validVersionDescriptions = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, HL7TableType> tableVersionTypes = new Dictionary<HL7Version, HL7TableType>();

        public InterpretationCodesAttribute()
        {
            // init the values for table version types
						tableVersionTypes[HL7Version.v23] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v231] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v24] = HL7TableType.User;
						tableVersionTypes[HL7Version.v25] = HL7TableType.User;
						tableVersionTypes[HL7Version.v251] = HL7TableType.User;
						tableVersionTypes[HL7Version.v26] = HL7TableType.User;
						tableVersionTypes[HL7Version.v27] = HL7TableType.User;
			
            
			// init the values for version codes
						validVersionCodes[HL7Version.v23] = new string[]{"<",">","A","AA","B","D","H","HH","I","L","LL","MS","N","null","R","S","U","VS","W"};
						validVersionCodes[HL7Version.v231] = new string[]{"L","H","LL","HH","<",">","N","A","AA","null","U","D","B","W","S","R","I","MS","VS"};
						validVersionCodes[HL7Version.v24] = new string[]{"L","H","LL","HH","<",">","N","A","AA","null","U","D","B","W","S","R","I","MS","VS"};
						validVersionCodes[HL7Version.v25] = new string[]{"L","H","LL","HH","<",">","N","A","AA","null","U","D","B","W","S","R","I","MS","VS"};
						validVersionCodes[HL7Version.v251] = new string[]{"L","H","LL","HH","<",">","N","A","AA","null","U","D","B","W","S","R","I","MS","VS"};
						validVersionCodes[HL7Version.v26] = new string[]{"L","H","LL","HH","<",">","N","A","AA","null","U","D","B","W","S","R","I","MS","VS"};
						validVersionCodes[HL7Version.v27] = new string[]{"L","H","LL","HH","<",">","N","A","AA","null","U","D","B","W","S","R","I","MS","VS","POS","NEG","IND","DET","ND","AC","TOX","QCF","RR","WR","NR"};
			
			// init the values for version descriptions
						validVersionDescriptions[HL7Version.v23] = new string[]{"Below absolute low-off instrument scale","Above absolute high-off instrument scale","Abnormal (applies to non-numeric results)","Very abnormal (applies to non-numeric units, analagous to panic limits for numeric units)","Better--use when direction not relevant","Significant change down","Above high normal","Above upper panic limits","Intermediate (microbiology sensitivies only)","Below low normal","Below lower panic limits","Moderately sensitive (microbiology sensitivies only)","Normal (applies to non-numeric results)","No range defined, or normal ranges don't apply","Resistant (microbiology sensitivies only)","Sensitive (microbiology sensitivies only)","Significant change up","Very sensitive (microbiology sensitivies only)","Worse--use when direction not relevant"};
						validVersionDescriptions[HL7Version.v231] = new string[]{"Below low normal","Above high normal","Below lower panic limits","Above upper panic limits","Below absolute low-off instrument scale","Above absolute high-off instrument scale","Normal (applies to non-numeric results)","Abnormal (applies to non-numeric results)","Very abnormal (applies to non-numeric units, analogous to panic limits for numeric units)","No range defined, or normal ranges don't apply","Significant change up","Significant change down","Better--use when direction not relevant","Worse--use when direction not relevant","Susceptible*","Resistant*","Intermediate*","Moderately susceptible*","Very susceptible*"};
						validVersionDescriptions[HL7Version.v24] = new string[]{"Below low normal","Above high normal","Below lower panic limits","Above upper panic limits","Below absolute low-off instrument scale","Above absolute high-off instrument scale","Normal (applies to non-numeric results)","Abnormal (applies to non-numeric results)","Very abnormal (applies to non-numeric units, analogous to panic limits for numeric units)","No range defined, or normal ranges don't apply","Significant change up","Significant change down","Better--use when direction not relevant","Worse--use when direction not relevant","Susceptible*","Resistant*","Intermediate*","Moderately susceptible*","Very susceptible*"};
						validVersionDescriptions[HL7Version.v25] = new string[]{"Below low normal","Above high normal","Below lower panic limits","Above upper panic limits","Below absolute low-off instrument scale","Above absolute high-off instrument scale","Normal (applies to non-numeric results)","Abnormal (applies to non-numeric results)","Very abnormal (applies to non-numeric units, analogous to panic limits for numeric units)","No range defined, or normal ranges don't apply","Significant change up","Significant change down","Better--use when direction not relevant","Worse--use when direction not relevant","Susceptible. Indicates for microbiology susceptibilities only.","Resistant. Indicates for microbiology susceptibilities only.","Intermediate. Indicates for microbiology susceptibilities only.","Moderately susceptible. Indicates for microbiology susceptibilities only.","Very susceptible. Indicates for microbiology susceptibilities only."};
						validVersionDescriptions[HL7Version.v251] = new string[]{"Below low normal","Above high normal","Below lower panic limits","Above upper panic limits","Below absolute low-off instrument scale","Above absolute high-off instrument scale","Normal (applies to non-numeric results)","Abnormal (applies to non-numeric results)","Very abnormal (applies to non-numeric units, analogous to panic limits for numeric units)","No range defined, or normal ranges don't apply","Significant change up","Significant change down","Better--use when direction not relevant","Worse--use when direction not relevant","Susceptible. Indicates for microbiology susceptibilities only.","Resistant. Indicates for microbiology susceptibilities only.","Intermediate. Indicates for microbiology susceptibilities only.","Moderately susceptible. Indicates for microbiology susceptibilities only.","Very susceptible. Indicates for microbiology susceptibilities only."};
						validVersionDescriptions[HL7Version.v26] = new string[]{"Below low normal","Above high normal","Below lower panic limits","Above upper panic limits","Below absolute low-off instrument scale","Above absolute high-off instrument scale","Normal (applies to non-numeric results)","Abnormal (applies to non-numeric results)","Very abnormal (applies to non-numeric units, analogous to panic limits for numeric units)","No range defined, or normal ranges don't apply","Significant change up","Significant change down","Better--use when direction not relevant","Worse--use when direction not relevant","Susceptible. Indicates for microbiology susceptibilities only.","Resistant. Indicates for microbiology susceptibilities only.","Intermediate. Indicates for microbiology susceptibilities only.","Moderately susceptible. Indicates for microbiology susceptibilities only.","Very susceptible. Indicates for microbiology susceptibilities only."};
						validVersionDescriptions[HL7Version.v27] = new string[]{"Below low normal","Above high normal","Below lower panic limits","Above upper panic limits","Below absolute low-off instrument scale","Above absolute high-off instrument scale","Normal (applies to non-numeric results)","Abnormal (applies to non-numeric results)","Very abnormal (applies to non-numeric units, analogous to panic limits for numeric units)","No range defined, or normal ranges don't apply","Significant change up","Significant change down","Better-use when direction not relevant","Worse-use when direction not relevant","Susceptible. Indicates for microbiology susceptibilities only.","Resistant. Indicates for microbiology susceptibilities only.","Intermediate. Indicates for microbiology susceptibilities only.","Moderately susceptible. Indicates for microbiology susceptibilities only.","Very susceptible. Indicates for microbiology susceptibilities only.","Positive","Negative","Indeterminate","Detected","Not Detected","Anti-complementary substances present","Cytotoxic substance present","Quality Control Failure","Reactive","Weakly reactive","Non-reactive"};
			            

        }

        
        public override ValidationIssue[] RunRule(string name, object owningObject, object value)
        {
            //todo: check if the value is valid in the current version
            //if the value is not valid in the current version, add it as a validation issue


            return new ValidationIssue[0];
        }
    }
}
